<?php


namespace app\partneradmin\controller;


use app\common\controller\partneradmin\Base;

class Payconfig extends Base
{
    protected $noNeedLogin = [];

    protected $model;


    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\partneradmin\model\PayConfig;
    }


    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        if ($this->request->isPost()) {
            $page = $this->request->post('page', 1);
            $size = $this->request->post('page_size', 10);
            $sort = $this->request->post('sort', 'id');
            $order = $this->request->post('order', 'desc');
            $adminId = $this->request->post('admin_id', '');
            $switch = $this->request->post('switch', '');
            $country_config_id = $this->request->post('country_config_id', '');
            if ($country_config_id != '') {
                $where['country_config_id'] = $country_config_id;
            }
            if ($adminId != '') {
                $where['admin_id'] = $adminId;
            }
            if ($switch != '') {
                $where['switch'] = $switch;
            }
            $where['is_del'] = 0;
            $list = $this->model
                ->field('id,title,nickname,switch,is_default,create_time,point_position,channel_code,configjson,other_information,country_config_id')
                ->where($where)
                ->page($page, $size)
                ->order($sort, $order)
                ->select();
            foreach ($list as $key => $value) {
                $value['configjson'] = unserialize($value['configjson']);
                $list[$key] = $value;
            }
            $total = $this->model->where($where)->count('id');
            $totalPage = ceil($total / $size);
            $data = [
                'total' => $total,
                'list' => $list,
                'totalPage' => $totalPage
            ];
            $this->success('列表', '', $data);
        }
    }

    /**
     * 添加
     */
    public function add()
    {
        $this->error('添加失败！该模块合作方不允许添加');
    }

    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        $this->error('修改失败！该模块合作方不允许编辑');
    }

    /**
     * 详情
     */
    public function details($ids = null)
    {
        $row = $this->model->get($ids);
        if (!$row) {
            $this->error('未查询到数据！', '', '', 404);
        }
        $row['configjson'] = unserialize($row['configjson']);
        $this->success('详情数据', '', $row);
    }
}